package com.haier.a920changjingyanshidemo.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;

import com.haier.a920changjingyanshidemo.Base;
import com.haier.a920changjingyanshidemo.R;
import com.haier.a920changjingyanshidemo.cusromview.CustomSeekbar;
import com.haier.a920changjingyanshidemo.cusromview.ResponseOnTouch;

import java.util.ArrayList;

import am.widget.circleprogressbar.CircleProgressBar;

/**
 * Created by 01457215 on 2017/8/21.
 */

public class EnjoyHeatActivity extends Activity implements SeekBar.OnSeekBarChangeListener, ResponseOnTouch, View.OnClickListener {
    private ArrayList<String> volume_sections = new ArrayList<String>();
    private String number;
    private ImageView kaiguan_bt;
    private ImageView yuyue_bt;
    private CircleProgressBar circleProgressBar;
    private SeekBar firstBar;
    private CustomSeekbar customSeekBar;
    private RelativeLayout main_layout;
    private FrameLayout firstBar_contain;
    private TextView close_tv;
    private TextView setting_tv;
    private TextView title;
    private String topTitle;
    private TextView curr_tv_value;
    private TextView curr_tv;

    @Nullable
    @Override
    public View onCreateView(String name, Context context, AttributeSet attrs) {
        return super.onCreateView(name, context, attrs);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.activity_enjoyheat);
        Intent intent = getIntent();
        number = intent.getStringExtra("No");
        topTitle = intent.getStringExtra("title");

        findViewById();


    }

    private void findViewById() {
//        customSeekBar = (CustomSeekbar) findViewById(R.id.custom_seekbar);
//        volume_sections.add("静音");
//        volume_sections.add("低");
//        volume_sections.add("中");
//        volume_sections.add("高");
//        customSeekBar.initData(volume_sections);
//
//        customSeekBar.setResponseOnTouch(this);//activity实现了下面的接口ResponseOnTouch，每次touch会回调onTouchResponse


        main_layout = (RelativeLayout) findViewById(R.id.main_layout);
        firstBar_contain = (FrameLayout) findViewById(R.id.firstBar_contain);
        title = (TextView) findViewById(R.id.title);
        if (topTitle != null) {
            title.setText(topTitle + "地暖");
        }
        close_tv = (TextView) findViewById(R.id.close_tv);
        setting_tv = (TextView) findViewById(R.id.setting_tv);
        curr_tv_value = (TextView) findViewById(R.id.curr_tv_value);
        curr_tv = (TextView) findViewById(R.id.curr_tv);
        firstBar = (SeekBar) findViewById(R.id.firstBar);
        firstBar.setOnSeekBarChangeListener(this);
        circleProgressBar = (CircleProgressBar) findViewById(R.id.circleProgressBar);
        kaiguan_bt = (ImageView) findViewById(R.id.kaiguan);
        kaiguan_bt.setOnClickListener(this);
        yuyue_bt = (ImageView) findViewById(R.id.yuyue);
        circleProgressBar.setDialVisibility(View.INVISIBLE);
        circleProgressBar.setProgressMode(CircleProgressBar.ProgressMode.PROGRESS);
        circleProgressBar.animationToProgress(30);//设置进度值
        circleProgressBar.setProgress(firstBar.getProgress());
        circleProgressBar.setProgressSize(10);
        circleProgressBar.setBackgroundSize(13);
        circleProgressBar.setMax(30);
        circleProgressBar.setProgressValueTextColor(Color.WHITE);
        circleProgressBar.setShowProgressValue(false);
        setting_tv.setText("设置温度: " + firstBar.getProgress() + "℃");

        if (Base.isOpenDiNuan) {
            kaiguan_bt.setImageResource(R.mipmap.dinuan_on);
            isOn = true;
            main_layout.setBackgroundResource(R.mipmap.enjoeyheat_bg);
            close_tv.setVisibility(View.GONE);
            firstBar.setVisibility(View.VISIBLE);
            curr_tv.setVisibility(View.VISIBLE);
            curr_tv_value.setVisibility(View.VISIBLE);
            circleProgressBar.setBackgroundColor(Color.rgb(70, 89, 191));
            circleProgressBar.setProgress(circleProgressBar.getProgress());
            firstBar_contain.setVisibility(View.VISIBLE);
        } else {
            isOn = false;
            kaiguan_bt.setImageResource(R.mipmap.dinuan_off);
            main_layout.setBackgroundResource(R.mipmap.enjoyheat_bg_gray);
            circleProgressBar.setBottomText("");
            close_tv.setVisibility(View.VISIBLE);
            firstBar.setVisibility(View.GONE);
            circleProgressBar.setProgress(0);
            curr_tv.setVisibility(View.GONE);
            curr_tv_value.setVisibility(View.GONE);
            circleProgressBar.setBackgroundColor(Color.rgb(132, 132, 159));
            firstBar_contain.setVisibility(View.GONE);
        }

    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
        circleProgressBar.setProgress(i);
//        circleProgressBar.setLoadingText(i + "℃");
        setting_tv.setText("设置温度: " + i + "℃");

    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onTouchResponse(int volume) {
        Log.e("---", "onTouchResponse: " + volume);
//        customSeekBar.setProgress(volume);
    }

    private boolean isOn = true;

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.kaiguan:
                if (isOn) {
                    Base.isOpenDiNuan = false;
                    isOn = false;
                    kaiguan_bt.setImageResource(R.mipmap.dinuan_off);
                    main_layout.setBackgroundResource(R.mipmap.enjoyheat_bg_gray);
                    circleProgressBar.setBottomText("");
                    close_tv.setVisibility(View.VISIBLE);
                    firstBar.setVisibility(View.GONE);
                    circleProgressBar.setProgress(0);
                    curr_tv.setVisibility(View.GONE);
                    curr_tv_value.setVisibility(View.GONE);
                    circleProgressBar.setBackgroundColor(Color.rgb(132, 132, 159));
                    firstBar_contain.setVisibility(View.GONE);

                } else {
                    curr_tv.setVisibility(View.VISIBLE);
                    curr_tv_value.setVisibility(View.VISIBLE);
                    Base.isOpenDiNuan = true;
                    kaiguan_bt.setImageResource(R.mipmap.dinuan_on);
                    isOn = true;
                    main_layout.setBackgroundResource(R.mipmap.enjoeyheat_bg);
                    close_tv.setVisibility(View.GONE);
                    firstBar.setVisibility(View.VISIBLE);
                    circleProgressBar.setBackgroundColor(Color.rgb(70, 89, 191));
                    circleProgressBar.setProgress(firstBar.getProgress());
                    firstBar_contain.setVisibility(View.VISIBLE);

                }
                break;
        }
    }

    @Override
    public void finish() {
        setResult(RESULT_OK);
        super.finish();

    }
}
